FROM python:3.7-alpine3.10 AS Build

#更新Alpine的软件源为国内（清华大学）的站点，因为从默认官源拉取实在太慢了。。。
# RUN echo "https://mirrors.aliyun.com/alpine/v3.6/main/" > /etc/apk/repositories
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories

ADD . /code 
WORKDIR /code

COPY requirements.txt ./

COPY ./ ./

RUN apk add --no-cache gcc musl-dev libxslt-dev

# 安装依赖和删除本地包
RUN pip install -i  https://mirrors.aliyun.com/pypi/simple/ --no-cache-dir -r requirements.txt 
# 删除开发配置文件和收集静态文件
RUN python manage.py collectstatic --noinput                

# FROM gcr.io/distroless/python3-debian10
# COPY --from=build /code /code
# COPY --from=build /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.7/site-packages
# # COPY --from=build /usr/local/lib/libpython3.9m.so.1.0 /usr/local/lib64/
# # COPY --from=build /usr/local/lib/libpython3.9m.so.1.0 /usr/local/lib/

# # 复制 libpython3.7m.so.1.0 之后，需重新加载配置
# RUN /sbin/ldconfig -v
# WORKDIR /code

# ENV PYTHONPATH=/usr/local/lib/python3.7/site-packages
ENV LANG C.UTF-8
ENV TZ "Asia/Shanghai"
ENV PYTHONUNBUFFERED 1

EXPOSE 80

CMD ["python", "manage.py", "runserver", "0.0.0.0:80" ,"--insecure"]
